require 'gameserver'
require 'gameclient'
local class = require 'hump.class'
local gwee = require 'gwee.gwee'
local text = require 'utilities.text'

HostMenu = class{
  function(self, state, mainmenustate)
    self.state = state
    self.w = love.graphics.getWidth()
    self.h = love.graphics.getHeight()
    
    self.hoststate = self.state.new()
    self.hoststate.enter = self.enter
    self.hoststate.leave = self.leave
    self.hoststate.keypressed = self.keypressed
    self.hoststate.mousepressed = self.mousepressed
    self.hoststate.mousereleased = self.mousereleased
    self.hoststate.update = self.update
    self.hoststate.draw = self.draw
    
    self.mainmenustate = mainmenustate
    self.hoststate.server = GameServer()
    self.hoststate.server:planetNew()
    
    self.hoststate.group = gwee.Group(gwee.Box(self.w/2-100, self.h/2-100, 200, 200), gwee.VerticalLayout(5), 'Host Menu')
    self.hoststate.group:add(gwee.Button(function()
                                           self.client = GameClient(self.state, self.mainmenustate, self.hoststate.server, 'player1')
                                         end, 'Start Game'))
    
    self.state.switch(self.hoststate)
  end
}

function HostMenu:enter()
  self.group.enabled = true
end

function HostMenu:leave()
  self.group.enabled = false
end

function HostMenu:keypressed(key)
  gwee.keypressed(key)
end

function HostMenu:mousepressed(x, y, button)
  gwee.mousepressed(x, y, button)
end

function HostMenu:mousereleased(x, y, button)
  gwee.mousereleased(x, y, button)
end

function HostMenu:update(dt)
  gwee.update(dt)
end

function HostMenu:draw()
  text.drawCenterText('Gravit T', 0, 36)
  gwee.draw()
end
